package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-12 11:30
 **/
public class LeetCode5954 {

    public int minimumRefill(int[] plants, int capacityA, int capacityB) {
        int count = 0;
        int n = plants.length;
        int l = 0;
        int r = n - 1;
        int initA = capacityA;
        int initB = capacityB;
        while (l <= r) {
            if (l == r) {
                int max = Math.max(capacityA, capacityB);
                if (max < plants[l]) {
                    ++count;
                }
            } else {
                if (capacityA < plants[l]) {
                    ++count;
                    capacityA = initA;
                }

                if (capacityB < plants[r]) {
                    ++count;
                    capacityB = initB;

                }
                capacityA -= plants[l];
                capacityB -= plants[r];

            }
            l++;
            r--;
        }
        return count;
    }

    public static void main(String[] args) {
        LeetCode5954 code = new LeetCode5954();
        //System.out.println("code.minimumRefill(new int[]{2,2,3,3}, 5, 5) = " + code.minimumRefill(new int[]{2, 2, 3, 3}, 5, 5));
        System.out.println("code.minimumRefill(new int[]{2,2,3,3}, 5, 5) = " + code.minimumRefill(new int[]{2,2,3,3}, 3, 4));
    }

}
